package com.athuahua.spzx.test;

import cn.hutool.core.date.DateTime;
import com.alibaba.excel.EasyExcel;
import com.athuahua.spzx.entity.*;
import com.athuahua.spzx.mapper.*;
import com.athuahua.spzx.vo.product.CategoryExcelVo;
import com.athuahua.spzx.properties.JwtProperties;
import com.athuahua.spzx.utils.JwtUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.*;

/**
 * @Author: huahua
 * @Date: 2024/7/22 0022
 * @Time: 2:08
 * @Description:
 */
@SpringBootTest
public class test01 {
    @Resource
    private JwtProperties jwtProperties;
    @Resource
    private SysRoleMenuMapper sysRoleMenuMapper;
    @Resource
    private SysRoleMapper sysRoleMapper;
    @Resource
    private SysUserMapper sysUserMapper;
    @Resource
    private CategoryMapper categoryMapper;

    @Resource
    private SysOperLogMapper sysOperLogMapper;

    @Test
    public void logtest(){
        List<SysOperLog> sysOperLogs = sysOperLogMapper.selectList(null);
        System.out.println(sysOperLogs);
    }

    @Test
    public void jwttest(){
        System.out.println("hello jwt");
        Map<String, Object> claims = new HashMap<>();
        claims.put("userName", 1);
        String token = JwtUtil.createJWT(
                jwtProperties.getAdminSecretKey(), //key
                jwtProperties.getAdminTtl(), //过期时间
                claims);
        System.out.println(token);
    }

    @Test
    public void test2(){
        List<SysRoleMenu> sysRoleMenus = sysRoleMenuMapper.selectList(new LambdaQueryWrapper<SysRoleMenu>()
                .eq(SysRoleMenu::getMenuId, 33));


        System.out.println(sysRoleMenus);
    }

    @Test
    public void test3() {
//        List<SysRole> sysRoleMenus = sysRoleMapper.selectList(null);
//        for (SysRole sysRoleMenu : sysRoleMenus){
//            sysRoleMenu.setCreateTime(new DateTime());
//            sysRoleMenu.setUpdateTime(new DateTime());
//            sysRoleMapper.updateById(sysRoleMenu);
//        }

//        sysUserMapper.selectList(null).forEach(
//                sysUser -> {
//                    sysUser.setCreateTime(new DateTime());
//                    sysUser.setUpdateTime(new DateTime());
//                    sysUserMapper.updateById(sysUser);
//                }
//        );
        categoryMapper.selectList(null).forEach(
                category -> {
                    category.setCreateTime(new DateTime());
                    category.setUpdateTime(new DateTime());
                    categoryMapper.updateById(category);
                }
        );
    }

    @Test
    public void easyExcelReadTest(){
        //1.定义读取excel文件的位置
        String fineName = "E://资料//尚品珍选//01.xlsx";
        ExcelListener<CategoryExcelVo> excelListener = new ExcelListener<>();
        //2.调用方法
        EasyExcel.read(
                fineName,
                CategoryExcelVo.class,
                excelListener
        ).sheet().doRead();

        List<CategoryExcelVo> data = excelListener.getData();
        //3.打印数据
        data.forEach(System.out::println);

    }


    @Test
    public void easyExcelWriteTest(){
        List<CategoryExcelVo> list = new ArrayList<>();
        list.add(new CategoryExcelVo(1L, "手机","",0L,1,2));
        list.add(new CategoryExcelVo(1L, "电脑","",0L,1,2));
        list.add(new CategoryExcelVo(1L, "相机","",0L,1,2));
        list.add(new CategoryExcelVo(1L, "平板","",0L,1,2));

        EasyExcel.write( "E://资料//尚品珍选//02.xlsx", CategoryExcelVo.class)
                .sheet("分类数据")
                .doWrite(list);


    }
    //easyexcel官网地址:https://www.yuque.com/easyexcel/doc/easyexcel


}
